#include <cstdio>

int main(int argc, char const *argv[]) {
    bool child[1001];
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++)
        child[i] = true;
    int remain_child = n;

    int child_count = 0, index = 1;
    while(remain_child > 1){
        if(!child[(n + child_count) % n + 1]){
            child_count++;
            continue;
        }else{
            if(index % k == 0 || index % 10 == k){
                child[(n + child_count) % n + 1] = false;
                remain_child--;
            }
            index++;
            child_count++;
        }
    }
    int result = 0;
    for (int i = 1; i <= n; i++) {
        if(child[i]){
            result = i;
            break;
        }
    }
    printf("%d", result);
    return 0;
}